package com.lzh.others.java8.book.chapter_3_3常用流操作;

import java.util.Comparator;
import java.util.List;

import static java.util.Arrays.asList;

/**
 * 找出累计播放量最低的曲目
 * 比较需要传递一个Comparator比较器对象
 * java8提供了新的静态方法：comparing，可以快捷实现比较代码
 *
 * @author lzh
 */
public class MinAndMax {
    public static void main(String[] args) {
        List<Track> tracks = asList(new Track("Bakai", 524),
                new Track("Violets for Your Furs", 378),
                new Track("Time Was", 451));
        tracks.stream().min(Comparator.comparing(Track::getSalesVolume)).ifPresent(s -> System.out.println("s = " + s));
        tracks.stream().max(Comparator.comparing(Track::getSalesVolume)).ifPresent(s -> System.out.println("s = " + s));
    }
}
